package com.road.crawler.meizitu.crawler;

import java.util.List;

import com.geccocrawler.gecco.GeccoEngine;
import com.geccocrawler.gecco.annotation.Gecco;
import com.geccocrawler.gecco.annotation.Href;
import com.geccocrawler.gecco.annotation.HtmlField;
import com.geccocrawler.gecco.annotation.Request;
import com.geccocrawler.gecco.annotation.RequestParameter;
import com.geccocrawler.gecco.request.HttpGetRequest;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.spider.HtmlBean;

/**
 * @Description :
 * @FileName: SecondPage.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年3月29日 上午11:45:17
 * @Version:V1.00
 */
@Gecco(matchUrl = "https://www.tohomh123.com/f-1-{tagId}-----updatetime--{currPage}.html", pipelines = {"consolePipeline", "nextPagePipeline"})
public class SecondPage implements HtmlBean {

	private static final long serialVersionUID = 1L;

	@Request
	private HttpRequest request;
	
	// 分类ID
	@RequestParameter
	private String tagId;

	// 当前页码
	@RequestParameter
	private int currPage;
	
	// 分类名称
	@Href
	@HtmlField(cssPath = ".cat-list > dd > .active")
	private String tag;

	// 分类下的漫画列表
	@HtmlField(cssPath = ".box-body > ul > li")
	private List<Picture> pictures;
	
	// 分页链接
	@HtmlField(cssPath = ".page-pagination > ul > li")
	private List<PagePaginationUrl> pagePaginationUrls;
	
	// 下一页链接
	private String nextPageUrl;
	
	public List<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(List<Picture> pictures) {
		this.pictures = pictures;
	}

	public HttpRequest getRequest() {
		return request;
	}

	public void setRequest(HttpRequest request) {
		this.request = request;
	}

	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public String getTagId() {
		return tagId;
	}

	public void setTagId(String tagId) {
		this.tagId = tagId;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public List<PagePaginationUrl> getPagePaginationUrls() {
		return pagePaginationUrls;
	}

	public void setPagePaginationUrls(List<PagePaginationUrl> pagePaginationUrls) {
		this.pagePaginationUrls = pagePaginationUrls;
	}

	public String getNextPageUrl() {
		if (null != this.pagePaginationUrls && this.pagePaginationUrls.size() > 0) {
			for (int i = 0; i < this.pagePaginationUrls.size(); i++) {
				PagePaginationUrl pageUrl = this.pagePaginationUrls.get(i);
				if ("active".equals(pageUrl.getCssClass())) {
					int nextIndex = i + 1;
					if (nextIndex > this.pagePaginationUrls.size()) {
						return this.pagePaginationUrls.get(nextIndex).getUrl();
					}
					break;
				}
			}
		}
		return null;
	}

	public static void main(String[] args) {
		HttpGetRequest start = new HttpGetRequest("https://www.tohomh123.com/f-1-1-----updatetime--1.html");
		start.setCharset("GBK");
		GeccoEngine.create().classpath("com.road.crawler.meizitu").start(start).interval(2000).run();
	}

}
